$isRelease = $args[0] -eq "-r"
$noInteractive = $args[1] -eq "-ni"

# --- 配置 start
$oemList = Get-Content "$PSScriptRoot\oem_config.json" | ConvertFrom-Json

$msbuildPath = "D:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\MSBuild.exe"
$slnPath = "$PSScriptRoot\CRM.sln"
# --- 配置 end

Write-Host -NoNewline "请输入oem_id(不选为全部):"
$id = $(Read-Host).Trim()
if ($id -ne "") {
    $oemList = $oemList | Where-Object { $_.Id -eq $id }
}

$outputPath = ""

$oemList | ForEach-Object {
    if ($isRelease) {
        $outputPath = "-p:OutputPath=..\Release\$($_.Name)"
    }

    & $msbuildPath $slnPath -t:Client\Client -p:OemName=$($_.Name) -p:OemId=$($_.Id) $outputPath
}

# Test
#$oemList | ForEach-Object {
#    & $msbuildPath $slnPath -t:Client\Client:TestOem -p:OemName=$($_.Name) -p:OemId=$($_.Id)
#}
